package as2.model;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.junit.Test;

import as2.model.pojo.Order;

public class OrderService extends DataService {
	@SuppressWarnings("unchecked")
	public static List<Order> getAllOrders() {
		Session session = getSession();
		session.beginTransaction();
		List<Order> orders = (List<Order>) session.createCriteria(Order.class)
				.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
		session.getTransaction().commit();
		System.out.println(orders.size() + " orders fetched");
		return orders;
	}

	public static Order getOrder(Long orderId) {
		Session session = getSession();
		session.beginTransaction();
		Order order = (Order) session.get(Order.class, orderId);
		session.getTransaction().commit();

		return order;
	}

	@Test
	public void test() {
		System.out.println(getAllOrders());
	}
}
